/*
 * @Description: 组合api配置
 * @Date: 2024-09-30 09:52:18
 * @FilePath: \demod:\12electron\b站向军课程\electron-camera\src\renderer\src\composables\useConfig.ts
 */

import { ref } from 'vue'

type ConfigType = {
  deviceId: string
  page: string
  borderWidth: string
  borderColor: string
  shape: string
}
const initConfig = {
  deviceId: '', // 绑定的设备id
  page: 'camera', // 页面
  borderWidth: '10px', // 边框宽度
  borderColor: '', // 边框颜色
  shape: '' // 摄像头边框形状
}

export default () => {
  const cache = localStorage.getItem('config')
  const data = cache ? (JSON.parse(cache) as ConfigType) : initConfig
  const config = ref(data)

  const updateConfig = () => {
    const cache = localStorage.getItem('config')
    const data = cache ? (JSON.parse(cache) as ConfigType) : initConfig
    const config = ref(data)
    localStorage.setItem('config', JSON.stringify(config.value))
  }
  return { config, updateConfig }
}
